package com.wc.算法提高课.B第二章_搜索.Flood_Fill.城堡问题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/23 16:06
 * @description https://www.acwing.com/problem/content/1100/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 55, M = N * N;
    static int[][] g = new int[N][N];
    static int[] q = new int[M];
    static boolean[][] st = new boolean[N][N];
    static int[] dx = {0, -1, 0, 1}, dy = {-1, 0, 1, 0};
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                g[i][j] = sc.nextInt();
            }
        }
        int area = 0, cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!st[i][j]) {
                    area = Math.max(area, bfs(i, j));
                    cnt++;
                }
            }
        }
        out.println(cnt);
        out.println(area);
        out.flush();
    }

    static int bfs(int sx, int sy) {
        int hh = 0, tt = 0;
        q[0] = sx * N + sy;
        st[sx][sy] = true;
        int area = 0;
        while (hh <= tt) {
            int x = q[hh] / N, y = q[hh++] % N;
            area++;
            for (int i = 0; i < 4; i++) {
                if ((g[x][y] >> i & 1) == 1) continue;
                int a = x + dx[i], b = y + dy[i];
                if (a < 0 || a >= n || b < 0 || b >= m) continue;
                if (st[a][b]) continue;
                q[++tt] = a * N + b;
                st[a][b] = true;
            }
        }
        return area;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
